package com.chen.controller;

import com.chen.common.Result;
import com.chen.service.Impl.ContentServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/content")
@Api(value = "ContentController",tags = "爬取京东数据")
public class ContentController {
    @Autowired
    private ContentServiceImpl contentService;


    @GetMapping("/parse/{keywords}")
    @ApiOperation("爬取数据")
    public Result getBook(@PathVariable("keywords") String keywords) throws IOException {
        return Result.success(contentService.parseContent(keywords));
    }


    public List<Map<String, Object>> search( String keyword, int pageNo, int pageSize) throws IOException {
        return contentService.searchPage(keyword, pageNo, pageSize);
    }

    @GetMapping("/{keyword}")
    @ApiOperation("查询数据")
    public Result search1(  @PathVariable("keyword") String keyword,
                          @RequestParam(defaultValue = "1") int pageNo,
                          @RequestParam(defaultValue = "1000") int pageSize) throws IOException {
        return Result.success(search(keyword, pageNo, pageSize));
    }
}
